#include "motor_infor.h"
#include "adc_val.h"
#include "math.h"
motor_iabc_t REA_iabc;
motor_iab_t REA_ialbe;

void calrk_func(adc_transform_t* iabc,motor_iab_t* ialbe,motor_iabc_t* motor_iabc){
   float ia,ib,ic=0;
   float ialpha,ibeta = 0;
	
	motor_iabc->_ia = iabc->_cur_A;
	motor_iabc->_ib = iabc->_cur_B;
	motor_iabc->_ic = iabc->_cur_C;
	
   ia = iabc->_cur_A;
   ib = iabc->_cur_B;
   ic = iabc->_cur_C;
    
   ialpha = ia*2.f/3.f-(ib+ic)/3.f;
   ibeta = (ib-ic)*sqrt(3.f)/3.f;

   ialbe->_ial = ialpha;
   ialbe->_ibe = ibeta;
}

void park_func(motor_iab_t* ialbe,float theta,motor_idq_t* idq){
   float ialpha,ibeta;
   float id,iq=0;
   ialpha = ialbe->_ial;
   ibeta = ialbe->_ibe;

   id = ialpha *cos(theta)+ibeta*sin(theta);
   iq = -ialpha * sin(theta)+ibeta *cos(theta);

   idq->_id = id;
   idq->_iq = iq;
}

// void invpark(float theta ,foc_infor_t* foc_cal){
//    float ualpha,ubeta = 0;
//    float ud,uq;
//    ud = foc_cal->voltage_ud_uq._ud;
//    uq = foc_cal->voltage_ud_uq._uq;

//    ualpha = cos(theta)*ud-sin(theta)*uq;
//    ubeta = sin(theta)*ud+cos(theta)*uq;

//    foc_cal->voltage_alpha_beta._ualpha = ualpha;
//    foc_cal->voltage_alpha_beta._ubeta = ubeta;
// }
